package com.lipuwater.agent.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.view.View;

import com.lipuwater.agent.R;
import com.lipuwater.agent.app.base.ui.BaseLayoutActivity;
import com.lipuwater.agent.ui.widget.HintEditText;

import butterknife.Bind;
import butterknife.ButterKnife;


public class EditTextActivity extends BaseLayoutActivity implements View.OnClickListener {
    @Bind(R.id.edit_text)
    HintEditText editText;

    private int resultCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setMyContentView(R.layout.activity_edit_text);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        Intent intent = getIntent();
        String content = intent.getStringExtra("content");
        resultCode = intent.getIntExtra("resultCode", 100);
        viewToolbarShadow.setVisibility(View.VISIBLE);
        initTitle(R.drawable.icon_aleft, intent.getStringExtra("title"));
        setTitleRight(0, "确定");
        if (content != null && !content.equals("")) {
            editText.setText(content);
        }
        editText.setHint(intent.getStringExtra("hint"));
        editText.setStrCount(intent.getIntExtra("count", 20));
        if (intent.getIntExtra("input_type", 0) != 0) {
            editText.setInputType(intent.getIntExtra("input_type", 0));
        }
        if (intent.getBooleanExtra("password", false)) {
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
        layout_right.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.putExtra("data", editText.getText().toString());
        setResult(resultCode, intent);
        finish();
    }
}
